<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Step 2: Creating the graph</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch34.html" title="Chapter 34. Showing SPAM statistics"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Step 2: Creating the graph</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 34. Showing SPAM statistics</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Step 2: Creating the graph"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2620783"></a>Step 2: Creating the graph</h2></div></div></div>
            
            <p>We will use a basic accumulated bar graphs with a text scale and integer y-scale.
                The remainder of the script should be fairly self explanatory since this is a
                straightforward graph with no "tricks".</p>
            <p>
                </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">/*</span><span class="hl-comment">*
* Class SpamGraph
</span><span class="hl-comment">*/</span><span class="hl-code">
</span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">SpamGraph</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-var">$iWidth</span><span class="hl-code">, </span><span class="hl-var">$iHeight</span><span class="hl-code">;
    </span><span class="hl-comment">/*</span><span class="hl-comment">*
    * Constructor
    * 
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">$aWidth Width of generated graph
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">$aHeight Height of generated graph
    *</span><span class="hl-inlinedoc"> @return </span><span class="hl-comment">SpamGraph 
    </span><span class="hl-comment">*/</span><span class="hl-code">
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">__construct</span><span class="hl-brackets">(</span><span class="hl-var">$aWidth</span><span class="hl-code">,</span><span class="hl-var">$aHeight</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-var">$this</span><span class="hl-code">-&gt;</span><span class="hl-identifier">iWidth</span><span class="hl-code"> = </span><span class="hl-var">$aWidth</span><span class="hl-code">;
        </span><span class="hl-var">$this</span><span class="hl-code">-&gt;</span><span class="hl-identifier">iHeight</span><span class="hl-code"> = </span><span class="hl-var">$aHeight</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code"> 
    </span><span class="hl-comment">/*</span><span class="hl-comment">*
    * Create an accumulated bar graph
    * 
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">string $aFile File to write graph to
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">array $aXData Date x-labels
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">array $aYData Spam data 1 (/dev/null)
    *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">array $aY2Data Spam data 2 (Spam folder)
    </span><span class="hl-comment">*/</span><span class="hl-code">
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$aFile</span><span class="hl-code">,</span><span class="hl-var">$aXData</span><span class="hl-code">,</span><span class="hl-var">$aYData</span><span class="hl-code">,</span><span class="hl-var">$aY2Data</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
 
        </span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">Graph</span><span class="hl-brackets">(</span><span class="hl-var">$this</span><span class="hl-code">-&gt;</span><span class="hl-identifier">iWidth</span><span class="hl-code">,</span><span class="hl-var">$this</span><span class="hl-code">-&gt;</span><span class="hl-identifier">iHeight</span><span class="hl-brackets">)</span><span class="hl-code">;    
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMargin</span><span class="hl-brackets">(</span><span class="hl-number">40</span><span class="hl-code">,</span><span class="hl-number">20</span><span class="hl-code">,</span><span class="hl-number">50</span><span class="hl-code">,</span><span class="hl-number">110</span><span class="hl-brackets">)</span><span class="hl-code">; 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetScale</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">textint</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMarginColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">khaki2@0.6</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetPos</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.5</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.97</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">center</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">bottom</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLayout</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFillColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_NORMAL</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Identified spams</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMargin</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_NORMAL</span><span class="hl-code">,</span><span class="hl-number">14</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">subtitle</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">(Updated: </span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-identifier">date</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">j M Y, H:i</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string"> T)</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">subtitle</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMargin</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">subtitle</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_ITALIC</span><span class="hl-code">,</span><span class="hl-number">11</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">xaxis</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetTickLabels</span><span class="hl-brackets">(</span><span class="hl-var">$aXData</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">xaxis</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_NORMAL</span><span class="hl-code">,</span><span class="hl-number">8</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">xaxis</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLabelAngle</span><span class="hl-brackets">(</span><span class="hl-number">45</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">yaxis</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_NORMAL</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">yscale</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetGrace</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$bar1</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">BarPlot</span><span class="hl-brackets">(</span><span class="hl-var">$aYData</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$bar1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFillGradient</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">darkred:1.2</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">darkred:0.7</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-identifier">GRAD_VER</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$bar1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLegend</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">To &quot;/dev/null&quot;</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$bar2</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">BarPlot</span><span class="hl-brackets">(</span><span class="hl-var">$aY2Data</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$bar2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFillGradient</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">orange</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">orange:0.7</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-identifier">GRAD_VER</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$bar2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLegend</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">To Spam folder</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-var">$abar</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">AccBarPlot</span><span class="hl-brackets">(</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-var">$bar1</span><span class="hl-code">,</span><span class="hl-var">$bar2</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$abar</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Show</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$abar</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFormat</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">%d</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$abar</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$aFile</span><span class="hl-brackets">)</span><span class="hl-code">;
        
        </span><span class="hl-identifier">syslog</span><span class="hl-brackets">(</span><span class="hl-identifier">LOG_INFO</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">Created spam image in </span><span class="hl-var">$aFile</span><span class="hl-string">.</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; 
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
  
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
            </p>
        </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch34.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
